package com.sx.manage.controller.function;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sx.manage.biz.function.button.IMFunctionInfoBiz;
import com.sx.manage.controller.base.MBaseController;
import com.sx.manage.service.function.IMBaseFunctionInfoService;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.model.constants.MDataStatusType;
import com.sx.model.manage.mybatis.form.function.MFunctionInfoForm;
import com.sx.model.manage.mybatis.vo.function.MFunctionInfoVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;
import com.sx.model.manage.mybatis.vo.result.ResultObjectVO;



/**
 * 模块信息 控制器
 * @author zhenzhanlong
 *
 */
@Controller
@RequestMapping("/function_info")
public class MFunctionInfoController extends MBaseController{
	/**
	 * 日志
	 */
	private Logger log = LoggerFactory.getLogger(this.getClass());
	
	@Resource(name="mFunctionInfoBizImpl")
	private IMFunctionInfoBiz mFunctionInfoBizImpl;
	

	@Resource(name="mBaseFunctionInfoServiceImpl")
	private IMBaseFunctionInfoService mBaseFunctionInfoServiceImpl;

	/***
	 * 功能信息列表
	 * @return
	 */
	@RequestMapping(value="function_list_view")
	public ViewAndModel allFunctionlist(){
		log.info("模块信息列表界面");
		ViewAndModel funView = new ViewAndModel(request,cache);
						funView.setViewName("function/functionList");
		return funView;
		
	}
	
	/**
	 * 功能信息添加界面
	 * @param form
	 * @return
	 */
	@RequestMapping(value="view_add")
	public ViewAndModel view_add(MFunctionInfoForm form){
		log.info("模块信息添加界面form={}",form);
		ViewAndModel funView = new ViewAndModel(request,cache);
					    funView.setViewName("function/addFunction");
					    
		ResultListVO<MFunctionInfoVO> result = mBaseFunctionInfoServiceImpl.get_functionList( form );
						
		funView.addObject("functionVO", new MFunctionInfoVO() );
		funView.addObject("functionList", result.getData() );
		return funView;
	}
	/**获取模块信息列表*/
	@RequestMapping(value="view_edit/{id}")
	public ViewAndModel view_edit(@PathVariable Long id){
		log.info("模块信息编辑界面id={}",id);
		ViewAndModel funView = new ViewAndModel(request,cache);
						funView.setViewName("function/addFunction");
						
		ResultObjectVO<MFunctionInfoVO> result = mBaseFunctionInfoServiceImpl.get_functionById(id);
		
		funView.addObject("functionVO", result.getObjVo() );	
		
	
		 MFunctionInfoForm form = new MFunctionInfoForm();
		             form.setId(id);
		ResultListVO<MFunctionInfoVO> listRes = mBaseFunctionInfoServiceImpl.get_functionList( form );
		
		funView.addObject("functionList", listRes.getData() );
		return funView;
	}
	/**获取模块信息列表*/
	@RequestMapping(value="function_save")
	@ResponseBody
	public  ResultListVO<MFunctionInfoVO> function_save( MFunctionInfoForm form ,BindingResult errors){
		log.info("模块信息保存操作form={}",form);
		//错误信息提示 ，手动校验 数据格式(第一种方式)
		String error = this.fieldValidate(form, errors); 
		if( null != error){
			return new  ResultListVO<>(false,null,error);
		}
		
		return this.mFunctionInfoBizImpl.save_function(form,loginConsumer());
	}
	/**获取模块信息列表*/
	@RequestMapping(value="function_list")
	@ResponseBody
	public ResultListVO<MFunctionInfoVO> function_list(MFunctionInfoForm form){
		log.info("模块信息集合form={}",form);
		return mBaseFunctionInfoServiceImpl.get_functionList(form);
	}
	/**获取模块信息列表*/
	@RequestMapping(value="function_page")
	@ResponseBody
	public ResultListVO<MFunctionInfoVO> function_page(MFunctionInfoForm form){
		log.info("模块信息列表数据作form={}",form);
		return mBaseFunctionInfoServiceImpl.get_functionPage(form);
	}
	/****启用**/
	@RequestMapping(value="function_enable")  ///@PathVariable 
	@ResponseBody
	public ResultBooleanVO function_enable(Long id  ){
		log.info("模块信息启用id={}",id);
		return mFunctionInfoBizImpl.update_functionStatus(new Long[]{id},MDataStatusType.DATA_AVAILABLE,loginConsumer());
	} 
	/****禁用 @PathVariable  */
	@RequestMapping(value="function_disable")  
	@ResponseBody
	public ResultBooleanVO function_disable(Long id  ){
		log.info("模块信息禁用id={}",id);
		return mFunctionInfoBizImpl.update_functionStatus(new Long[]{id},MDataStatusType.DATA_DISABLE,loginConsumer());
	} 

	public IMFunctionInfoBiz getmFunctionInfoBizImpl() {
		return mFunctionInfoBizImpl;
	}

	public void setmFunctionInfoBizImpl(IMFunctionInfoBiz mFunctionInfoBizImpl) {
		this.mFunctionInfoBizImpl = mFunctionInfoBizImpl;
	}

	public IMBaseFunctionInfoService getmBaseFunctionInfoServiceImpl() {
		return mBaseFunctionInfoServiceImpl;
	}

	public void setmBaseFunctionInfoServiceImpl(IMBaseFunctionInfoService mBaseFunctionInfoServiceImpl) {
		this.mBaseFunctionInfoServiceImpl = mBaseFunctionInfoServiceImpl;
	}
	

		
}
